Radar Host Communication library  2020.08.13
EndpointRadarD2GL.c
Go to the documentation of this file.
1 
10 /* ===========================================================================
11 ** Copyright (C) 2017 - 2021 Infineon Technologies AG
12 ** All rights reserved.
13 ** ===========================================================================
14 **
15 ** ===========================================================================
16 ** This document contains proprietary information of Infineon Technologies AG.
17 ** Passing on and copying of this document, and communication of its contents
18 ** is not permitted without Infineon's prior written authorisation.
19 ** ===========================================================================
20 */
21 
22 /*
23 ==============================================================================
24  1. INCLUDE FILES
25 ==============================================================================
26 */
27 #include "EndpointRadarD2GL.h"
28 #define __PROTOCOL_INCLUDE_ENDPOINT_ONLY_API__
29 #include "Protocol_internal.h"
30 #undef __PROTOCOL_INCLUDE_ENDPOINT_ONLY_API__
31 #include <stdlib.h>
32 #include <string.h>
33 #include <stdio.h>
34 /*
35 ==============================================================================
36  2. LOCAL DEFINITIONS
37 ==============================================================================
38 */
39 
52 #define MSG_PARA_VALUES_REQ 0x50
53 #define MSG_PARA_VALUES_CNF 0x51
54 #define MSG_PARA_VALUES_DEF_REQ 0x52
55 #define MSG_PARA_VALUES_DEF_CNF 0x53
56 #define MSG_PARA_SET_VALUES_REQ 0x54
57 #define MSG_RESULT_REQ 0x55
58 #define MSG_RESULT_CNF 0x56
61 #define FMCW_MSG_GET_SHIELD_INFO_REQ 0x57
62 #define FMCW_MSG_GET_SHIELD_INFO_CNF 0x58
63 #define FMCW_MSG_GET_SHIELD_INFO_CNF_V2 0x63
64 
65 
66 #define FMCW_MSG_GET_RAW_DATA_REQ 0x59
67 #define FMCW_MSG_GET_RAW_DATA_CNF 0x6A
68 
69 #define MSG_ADV_RESULT_REQ 0x61
70 #define MSG_ADV_RESULT_CNF 0x62
71 
72 
75 /*
76 ==============================================================================
77  5. LOCAL FUNCTION PROTOTYPES
78 ==============================================================================
79 */
84 extern const char* ep_radar_get_error_code_description(uint16_t error_code);
85 
101 static void parse_payload(int32_t protocol_handle, uint8_t endpoint,
102  const uint8_t* payload, uint16_t payload_size);
103 
104 /*
105 ==============================================================================
106  4. DATA
107 ==============================================================================
108 */
122 const Endpoint_Definition_t ep_RadarD2GL_definition =
123 {
124  /*.type =*/ 0x544A5346, /* ASCII code 'TJSF' = D2GL-SC-FMCW (via "software controlled fmcw")*/
125  /*.min_version =*/ 1,
126  /*.max_version =*/ 1,
127  /*.description =*/ "ifxRadar D2GL SC FMCW",
128  /*.parse_payload =*/ parse_payload,
129  /*.get_status_descr =*/ ep_radar_get_error_code_description
130 };
131 
149 static fmcw_para_values_cnf_callback_t para_values_cnf_cb = NULL;
150 static void *para_values_cnf_ctx = NULL;
151 
152 static fmcw_para_values_def_cnf_callback_t para_values_def_cnf_cb = NULL;
153 static fmcw_para_values_def_cnf_ctx_t *para_values_def_cnf_ctx = NULL;
154 
155 static fmcw_result_cnf_callback_t result_cnf_cb = NULL;
156 static void *result_cnf_ctx = NULL;
157 
158 static fmcw_adv_result_cnf_callback_t adv_result_cnf_cb = NULL;
159 static void *adv_result_cnf_ctx = NULL;
160 
161 static fmcw_get_shield_info_cnf_callback_t fmcw_get_shield_info_cnf_cb = NULL;
162 static fmcw_get_shield_info_cnf_ctx_t *fmcw_get_shield_info_cnf_ctx = NULL;
163 
164 static get_raw_data_cnf_callback_t get_raw_data_cnf_cb = NULL;
165 static get_raw_data_cnf_ctx_t *get_raw_data_cnf_ctx = NULL;
166 
171 /*
172 ==============================================================================
173  6. LOCAL FUNCTIONS
174 ==============================================================================
175 */
176 
177 static int32_t parse_frame_info(int32_t protocol_handle, uint8_t endpoint,
178  const uint8_t* payload,
179  uint16_t payload_size)
180 {
181  get_raw_data_cnf_t frame_info;
182  uint32_t total_samples;
183  uint32_t expected_message_size;
184 
185  uint8_t header_size = 18;
186 
187  /* read header info from payload */
188  frame_info.frame_number =
189  protocol_read_payload_uint32(payload, 1);
190  frame_info.num_chirps = protocol_read_payload_uint32(payload, 5);
191  frame_info.num_rx_antennas =
192  protocol_read_payload_uint8(payload, 9);
193  frame_info.num_samples_per_chirp =
194  protocol_read_payload_uint32(payload, 10);
195  frame_info.rx_mask = protocol_read_payload_uint8(payload, 14);
196  frame_info.data_format =
197  (Rx_Data_Format_t)protocol_read_payload_uint8(payload, 15);
198  frame_info.adc_resolution =
199  protocol_read_payload_uint8(payload, 16);
200  frame_info.interleaved_rx =
201  protocol_read_payload_uint8(payload, 17);
202 
203  /* calculate expected message size */
204  total_samples = frame_info.num_chirps *
205  frame_info.num_samples_per_chirp *
206  frame_info.num_rx_antennas *
207  (frame_info.data_format == EP_RADAR_BASE_RX_DATA_REAL ? 1 : 2);
208 
209  expected_message_size = total_samples * frame_info.adc_resolution;
210  expected_message_size = header_size +
211  (expected_message_size >> 3) +
212  ((expected_message_size & 0x07) ? 1 : 0);
213 
214  if (payload_size == expected_message_size)
215  {
216  uint32_t sample_bit_mask = (1 << frame_info.adc_resolution) - 1;
217  const float norm_factor = 1.f / (float)sample_bit_mask;
218  float *sample_data = (float *)malloc(total_samples *
219  sizeof(float));
220  float *write_ptr = sample_data;
221 
222  uint16_t read_idx = header_size;
223  uint16_t read_bit_position = 0;
224 
225  while (total_samples)
226  {
227  uint32_t current_sample =
228  protocol_read_payload_uint16(payload, read_idx) >>
229  read_bit_position;
230  *write_ptr++ = (current_sample & sample_bit_mask) *
231  norm_factor;
232 
233  read_bit_position += frame_info.adc_resolution;
234  read_idx += read_bit_position >> 3;
235  read_bit_position &= 0x07;
236 
237  --total_samples;
238  }
239 
240  /* send frame info to callback */
241  frame_info.sample_data = sample_data;
242  get_raw_data_cnf_cb(get_raw_data_cnf_ctx, protocol_handle,
243  endpoint, &frame_info);
244  free(sample_data);
245  }
246 
247  return 1;
248 }
249 
250 static int32_t parse_para_values_cnf(int32_t protocol_handle, uint8_t endpoint,
251  const uint8_t* payload, uint16_t payload_size)
252 {
253  uint8_t payloadId = protocol_read_payload_uint8(payload, 0);
254 
255  if ((payloadId == MSG_PARA_VALUES_CNF) &&
256  (payload_size >= 26))
257  {
258  if (para_values_cnf_cb)
259  {
260  fmcw_para_values_t para_values;
261  uint16_t offset = 1;
262 
263  para_values.max_distance_m = protocol_read_payload_float32(&payload[0], offset);
264  offset += sizeof(float);
265  para_values.min_distance_m = protocol_read_payload_float32(&payload[0], offset);
266  offset += sizeof(float);
267  para_values.frame_time_sec = protocol_read_payload_float32(&payload[0], offset);
268  offset += sizeof(float);
269  para_values.number_of_samples_nu = protocol_read_payload_uint16(&payload[0], offset);
270  offset += sizeof(uint16_t);
271  para_values.hold_threshold = protocol_read_payload_uint32(&payload[0], offset);
272  offset += sizeof(uint32_t);
273  para_values.activation_threshold = protocol_read_payload_uint32(&payload[0], offset);
274  offset += sizeof(uint32_t);
275  para_values.number_of_chirps_per_frame = protocol_read_payload_uint8(&payload[0], offset);
276  offset += sizeof(uint8_t);
277  para_values.continuous_mode_bool = protocol_read_payload_uint8(&payload[0], offset);
278  offset += sizeof(uint8_t);
279  para_values.baseband_gain_stage_bool = protocol_read_payload_uint8(&payload[0], offset);
280  offset += sizeof(uint8_t);
281  if(payload_size >= offset + sizeof( float) )
282  {
283  para_values.pulse_repetition_rate_sec = protocol_read_payload_float32(&payload[0], offset);
284  offset += sizeof(float);
285  }
286  else
287  para_values.pulse_repetition_rate_sec = 0.0; // don't leave value uninitialized!
288  if (payload_size >= offset + sizeof(uint8_t))
289  {
290  uint8_t u8_activate_cfar = protocol_read_payload_uint8(&payload[0], offset);
291  para_values.activate_cfar = (u8_activate_cfar > 0 ? true : false);
292  offset += sizeof(uint8_t);
293  }
294  else
295  para_values.activate_cfar = false; // don't leave value uninitialized!
296 
297  /* send frame format to callback */
298  para_values_cnf_cb(para_values_cnf_ctx, protocol_handle,
299  endpoint, &para_values);
300  }
301  return 1;
302  }
303  else if ((payloadId == MSG_PARA_VALUES_DEF_CNF) &&
304  (payload_size > 1))
305  {
306  if (para_values_def_cnf_cb)
307  {
308  // TODO: move this out into a separate function!
309  fmcw_para_value_def_host_t para_value_def;
310 
311  // pre-init optional attribute
312  para_value_def.pulse_repetition_time_sec_lower_boundary = 0.0;
313  para_value_def.pulse_repetition_time_sec_upper_boundary = 0.0;
314  para_value_def.pulse_repetition_time_sec_step_size = 0.0;
315 
316 
317  uint16_t offset = 1; // skip message id
318  (void)protocol_read_payload_uint16(&payload[0], offset); // last_message_size not used
319  offset += sizeof(uint16_t);
320 
321  para_value_def.max_distance_m_lower_boundary = protocol_read_payload_float32(&payload[0], offset);
322  offset += sizeof(float);
323  para_value_def.max_distance_m_upper_boundary = protocol_read_payload_float32(&payload[0], offset);
324  offset += sizeof(float);
325  para_value_def.max_distance_m_step_size = protocol_read_payload_float32(&payload[0], offset);
326  offset += sizeof(float);
327 
328  para_value_def.min_distance_m_lower_boundary = protocol_read_payload_float32(&payload[0], offset);
329  offset += sizeof(float);
330  para_value_def.min_distance_m_upper_boundary = protocol_read_payload_float32(&payload[0], offset);
331  offset += sizeof(float);
332  para_value_def.min_distance_m_step_size = protocol_read_payload_float32(&payload[0], offset);
333  offset += sizeof(float);
334 
335  para_value_def.frame_time_sec_lower_boundary = protocol_read_payload_float32(&payload[0], offset);
336  offset += sizeof(float);
337  para_value_def.frame_time_sec_upper_boundary = protocol_read_payload_float32(&payload[0], offset);
338  offset += sizeof(float);
339  para_value_def.frame_time_sec_step_size = protocol_read_payload_float32(&payload[0], offset);
340  offset += sizeof(float);
341 
342  para_value_def.size_elems = protocol_read_payload_uint8( &payload[0], offset);
343  offset += sizeof(uint8_t);
344  para_value_def.p_sample_list = (uint16_t *)malloc(para_value_def.size_elems*sizeof(uint16_t));
345  for(uint16_t n= 0; n < para_value_def.size_elems; n++)
346  {
347  para_value_def.p_sample_list[n] = protocol_read_payload_uint16( &payload[0], offset);
348  offset += sizeof(uint16_t);
349  }
350 
351 
352  para_value_def.hold_threshold_lower_boundary = protocol_read_payload_uint32(&payload[0], offset);
353  offset += sizeof(uint32_t);
354  para_value_def.hold_threshold_upper_boundary = protocol_read_payload_uint32(&payload[0], offset);
355  offset += sizeof(uint32_t);
356  para_value_def.hold_threshold_step_size = protocol_read_payload_uint32(&payload[0], offset);
357  offset += sizeof(uint32_t);
358 
359  para_value_def.activation_threshold_lower_boundary = protocol_read_payload_uint32(&payload[0], offset);
360  offset += sizeof(uint32_t);
361  para_value_def.activation_threshold_upper_boundary = protocol_read_payload_uint32(&payload[0], offset);
362  offset += sizeof(uint32_t);
363  para_value_def.activation_threshold_step_size = protocol_read_payload_uint32(&payload[0], offset);
364  offset += sizeof(uint32_t);
365 
366  para_value_def.number_of_chirps_per_frame_lower_boundary = protocol_read_payload_uint8(&payload[0], offset);
367  offset += sizeof(uint8_t);
368  para_value_def.number_of_chirps_per_frame_upper_boundary = protocol_read_payload_uint8(&payload[0], offset);
369  offset += sizeof(uint8_t);
370  para_value_def.number_of_chirps_per_frame_step_size = protocol_read_payload_uint8(&payload[0], offset);
371  offset += sizeof(uint8_t);
372 
373  if( payload_size >= offset + sizeof(float) )
374  {
375  para_value_def.pulse_repetition_time_sec_lower_boundary = protocol_read_payload_float32(&payload[0], offset);
376  offset += sizeof(float);
377  }
378 
379  if( payload_size >= offset + sizeof(float) )
380  {
381  para_value_def.pulse_repetition_time_sec_upper_boundary = protocol_read_payload_float32(&payload[0], offset);
382  offset += sizeof(float);
383  }
384 
385  if( payload_size >= offset + sizeof(float) )
386  {
387  para_value_def.pulse_repetition_time_sec_step_size = protocol_read_payload_float32(&payload[0], offset);
388  offset += sizeof(float);
389  }
390 
391  /* send frame format to callback */
392  para_values_def_cnf_cb(para_values_def_cnf_ctx, protocol_handle,
393  endpoint, &para_value_def);
394 
395  // free-up memory!!
396  free(para_value_def.p_sample_list);
397 
398  }
399  return 1;
400  }
401  else if ((payloadId == MSG_RESULT_CNF) &&
402  (payload_size == 23))
403  {
404  if (result_cnf_cb)
405  {
406  fmcw_result_cnf_t result;
407 
408  uint16_t offset = 1;
409 
410  result.result_count = protocol_read_payload_uint32(&payload[0], offset);
411  offset += sizeof(uint32_t);
412  result.frame_number = protocol_read_payload_uint32(&payload[0], offset);
413  offset += sizeof(uint32_t);
414  result.range_m = protocol_read_payload_float32(&payload[0], offset);
415  offset += sizeof(float);
416  result.strength = protocol_read_payload_float32(&payload[0], offset);
417  offset += sizeof(float);
418  result.velocity_mps = protocol_read_payload_float32(&payload[0], offset);
419  offset += sizeof(float);
420  result.target_status = protocol_read_payload_uint8(&payload[0], offset);
421  offset += sizeof(uint8_t);
422  result.direction_of_movement = protocol_read_payload_uint8(&payload[0], offset);
423  offset += sizeof(uint8_t);
424 
425  /* send result to callback */
426  result_cnf_cb(result_cnf_ctx, protocol_handle,
427  endpoint, &result);
428 
429  }
430  return 1;
431  }
432  else if ((payloadId == MSG_ADV_RESULT_CNF) &&
433  (payload_size >1))
434  {
435  if (adv_result_cnf_cb)
436  {
437  fmcw_adv_result_cnf_t adv_result;
438 
439  uint16_t offset = 1;
440 
441  adv_result.result_count = protocol_read_payload_uint32(&payload[0], offset);
442  offset += sizeof(uint32_t);
443  adv_result.frame_number = protocol_read_payload_uint32(&payload[0], offset);
444  offset += sizeof(uint32_t);
445  adv_result.range_m = protocol_read_payload_float32(&payload[0], offset);
446  offset += sizeof(float);
447  adv_result.strength = protocol_read_payload_float32(&payload[0], offset);
448  offset += sizeof(float);
449  adv_result.velocity_mps = protocol_read_payload_float32(&payload[0], offset);
450  offset += sizeof(float);
451  adv_result.target_status = protocol_read_payload_uint8(&payload[0], offset);
452  offset += sizeof(uint8_t);
453  adv_result.direction_of_movement = protocol_read_payload_uint8(&payload[0], offset);
454  offset += sizeof(uint8_t);
455 
456  adv_result.num_activation_data = protocol_read_payload_uint16(&payload[0], offset);
457  offset += sizeof(uint16_t);
458  adv_result.p_activation_data = (float *)malloc(adv_result.num_activation_data*sizeof(float));
459  if (adv_result.num_activation_data > 0)
460  {
461  for (uint32_t i = 0; i < adv_result.num_activation_data; i++)
462  {
463  adv_result.p_activation_data[i] = protocol_read_payload_float32(&payload[0], offset);
464  offset += sizeof(float);
465  }
466  }
467 
468  adv_result.num_hold_data = protocol_read_payload_uint16(&payload[0], offset);
469  offset += sizeof(uint16_t);
470  adv_result.p_hold_data = (float *)malloc(adv_result.num_hold_data*sizeof(float));
471  if (adv_result.num_hold_data > 0)
472  {
473  for (uint32_t i = 0; i < adv_result.num_hold_data; i++)
474  {
475  adv_result.p_hold_data[i] = protocol_read_payload_float32(&payload[0], offset);
476  offset += sizeof(float);
477  }
478  }
479 
480  /* send result to callback */
481  adv_result_cnf_cb(adv_result_cnf_ctx, protocol_handle,
482  endpoint, &adv_result);
483 
484  if (adv_result.p_activation_data != NULL)
485  {
486  free(adv_result.p_activation_data);
487  }
488  if (adv_result.p_hold_data != NULL)
489  {
490  free(adv_result.p_hold_data);
491  }
492 
493  }
494  return 1;
495  }
496  else if((payloadId == FMCW_MSG_GET_SHIELD_INFO_CNF) && (payload_size >1))
497  {
498  fmcw_get_shield_info_cnf_t shield_info = {0};
499  uint16_t offset = 1;
500 
501  if( fmcw_get_shield_info_cnf_cb )
502  {
503 
504  shield_info.rf_frequency_khz = protocol_read_payload_uint32(&payload[0], offset);
505  offset += sizeof(uint32_t);
506  shield_info.major_version = protocol_read_payload_uint8(&payload[0], offset);
507  offset += sizeof(uint8_t);
508  shield_info.minor_version = protocol_read_payload_uint8(&payload[0], offset);
509  offset += sizeof(uint8_t);
510  shield_info.num_tx_antenna = protocol_read_payload_uint8(&payload[0], offset);
511  offset += sizeof(uint8_t);
512  shield_info.num_rx_antenna = protocol_read_payload_uint8(&payload[0], offset);
513  offset += sizeof(uint8_t);
514 
515  shield_info.bandwidth_mhz = 200; // Assume 200 value for old firmware
516 
517  offset += protocol_read_payload_string(&payload[0], offset, &shield_info.rf_shield_type_id); // NOTE: Called board id in FW
518 
519  offset += protocol_read_payload_string(&payload[0], offset, &shield_info.description);
520 
521  offset += protocol_read_payload_string(&payload[0], offset, &shield_info.modulation);
522 
523  fmcw_get_shield_info_cnf_cb(fmcw_get_shield_info_cnf_ctx, protocol_handle, endpoint, &shield_info);
524 
525  if (shield_info.rf_shield_type_id != NULL)
526  {
527  free(shield_info.rf_shield_type_id);
528  }
529  if (shield_info.description != NULL)
530  {
531  free(shield_info.description);
532  }
533  if (shield_info.modulation != NULL)
534  {
535  free(shield_info.modulation);
536  }
537  }
538  }
539  else if ((payloadId == FMCW_MSG_GET_SHIELD_INFO_CNF_V2) && (payload_size > 1))
540  {
541  fmcw_get_shield_info_cnf_t shield_info = { 0 };
542  uint16_t offset = 1;
543 
544  if (fmcw_get_shield_info_cnf_cb)
545  {
546  shield_info.rf_frequency_khz = protocol_read_payload_uint32(&payload[0], offset);
547  offset += sizeof(uint32_t);
548  shield_info.bandwidth_mhz = protocol_read_payload_uint32(&payload[0], offset);
549  offset += sizeof(uint32_t);
550  shield_info.major_version = protocol_read_payload_uint8(&payload[0], offset);
551  offset += sizeof(uint8_t);
552  shield_info.minor_version = protocol_read_payload_uint8(&payload[0], offset);
553  offset += sizeof(uint8_t);
554  shield_info.num_tx_antenna = protocol_read_payload_uint8(&payload[0], offset);
555  offset += sizeof(uint8_t);
556  shield_info.num_rx_antenna = protocol_read_payload_uint8(&payload[0], offset);
557  offset += sizeof(uint8_t);
558 
559  offset += protocol_read_payload_string(&payload[0], offset, &shield_info.rf_shield_type_id); // NOTE: Called board id in FW
560 
561  offset += protocol_read_payload_string(&payload[0], offset, &shield_info.description);
562 
563  offset += protocol_read_payload_string(&payload[0], offset, &shield_info.modulation);
564  if (payload_size >= offset + sizeof(float))
565  {
566  shield_info.up_chirp_time_s = protocol_read_payload_float32(&payload[0], offset );
567  offset += sizeof(float);
568  }
569 
570  fmcw_get_shield_info_cnf_cb(fmcw_get_shield_info_cnf_ctx, protocol_handle, endpoint, &shield_info);
571 
572  if (shield_info.rf_shield_type_id != NULL)
573  {
574  free(shield_info.rf_shield_type_id);
575  }
576  if (shield_info.description != NULL)
577  {
578  free(shield_info.description);
579  }
580  if (shield_info.modulation != NULL)
581  {
582  free(shield_info.modulation);
583  }
584 
585  }
586  }
587  else if ((payloadId == FMCW_MSG_GET_RAW_DATA_CNF) && (payload_size >= 18))
588  {
589  parse_frame_info(protocol_handle, endpoint, payload, payload_size);
590  }
591  else
592  {
593  printf("not found\n");
594  }
595 
596  return 0;
597 }
598 
599 
600 static void parse_payload(int32_t protocol_handle, uint8_t endpoint,
601  const uint8_t* payload, uint16_t payload_size)
602 {
603  /* try to parse payload for all supported message types, stop when parsing
604  * was successful
605  */
606  if (parse_para_values_cnf(protocol_handle, endpoint,
607  payload, payload_size))
608  return;
609 }
610 
611 /*
612 ==============================================================================
613  7. EXPORTED FUNCTIONS
614 ==============================================================================
615 */
616 
617 int32_t ep_radar_d2gl_scfmcw_is_compatible_endpoint(int32_t protocol_handle,
618  uint8_t endpoint)
619 {
620  return protocol_is_endpoint_compatible(protocol_handle, endpoint,
622 }
623 
624 //----------------------------------------------------------------------------
625 //----------------------------------------------------------------------------
626 
628  void* p_context, void **prev_context)
629 {
630  /* save and return previous cb and context, so that it could be restore aferwards! */
631  fmcw_para_values_cnf_callback_t previous_cb = para_values_cnf_cb;
632  if (prev_context != NULL)
633  *prev_context = para_values_cnf_ctx;
634 
635  para_values_cnf_cb = callback;
636  para_values_cnf_ctx = p_context;
637  return previous_cb;
638 }
639 
640 
643 {
644  para_values_def_cnf_cb = callback;
645  para_values_def_cnf_ctx = p_context;
646 }
647 
649  void* p_context)
650 {
651  result_cnf_cb = callback;
652  result_cnf_ctx = p_context;
653 }
654 
656  void* p_context)
657 {
658  adv_result_cnf_cb = callback;
659  adv_result_cnf_ctx = p_context;
660 }
661 
664 {
665  fmcw_get_shield_info_cnf_cb = callback;
666  fmcw_get_shield_info_cnf_ctx = p_context;
667 }
668 
669 
671  void* p_context)
672 {
673  get_raw_data_cnf_cb = callback;
674  get_raw_data_cnf_ctx = p_context;
675 }
676 
677 
678 
679 int32_t ep_radar_d2gl_scfmcw_para_value_req(int32_t protocol_handle, uint8_t endpoint)
680 {
681  /* build message to send */
682  uint8_t cmd_message[1];
683 
684  protocol_write_payload_uint8(cmd_message, 0, MSG_PARA_VALUES_REQ);
685 
686  /* send message and process received response */
687  return protocol_send_and_receive(protocol_handle, endpoint,
689  cmd_message, sizeof(cmd_message));
690 }
691 
692 int32_t ep_radar_d2gl_scfmcw_para_value_def_req(int32_t protocol_handle, uint8_t endpoint)
693 {
694  /* build message to send */
695  uint8_t cmd_message[1];
696 
697  protocol_write_payload_uint8(cmd_message, 0, MSG_PARA_VALUES_DEF_REQ);
698 
699  /* send message and process received response */
700  return protocol_send_and_receive(protocol_handle, endpoint,
702  cmd_message, sizeof(cmd_message));
703 }
704 
705 int32_t ep_radar_d2gl_scfmcw_para_set_value_req(int32_t protocol_handle, uint8_t endpoint, fmcw_para_values_t *p_data)
706 {
707  /* build message to send */
708  uint8_t cmd_message[100];
709  uint16_t offset = 0;
710 
711  offset += protocol_write_payload_uint8(cmd_message, offset, MSG_PARA_SET_VALUES_REQ);
712 
713  offset += protocol_write_payload_float32(cmd_message, offset, p_data->max_distance_m);
714  offset += protocol_write_payload_float32(cmd_message, offset, p_data->min_distance_m);
715  offset += protocol_write_payload_float32(cmd_message, offset, p_data->frame_time_sec);
716  offset += protocol_write_payload_uint16(cmd_message, offset, p_data->number_of_samples_nu);
717  offset += protocol_write_payload_uint32(cmd_message, offset, p_data->hold_threshold);
718  offset += protocol_write_payload_uint32(cmd_message, offset, p_data->activation_threshold);
719  offset += protocol_write_payload_uint8(cmd_message, offset, p_data->number_of_chirps_per_frame);
720  offset += protocol_write_payload_uint8(cmd_message, offset, p_data->continuous_mode_bool);
721  offset += protocol_write_payload_uint8(cmd_message, offset, p_data->baseband_gain_stage_bool);
722  offset += protocol_write_payload_float32(cmd_message, offset, p_data->pulse_repetition_rate_sec);
723  offset += protocol_write_payload_uint8(cmd_message, offset, p_data->activate_cfar);
724 
725  /* send message and process received response */
726  return protocol_send_and_receive(protocol_handle, endpoint,
728  cmd_message, offset);
729 }
730 
731 /*
732  * if repeat_count is 0xFFFF.FFFF the results will be continuously provided, unless stopped (with repeat_count set to 0)
733  * if repeat_count is 1, only a single result is returned, and the next result needs to be retriggerd
734  * in case you like to avoid extra latency, by the round trip request, set the result cnt to 0xfffffffff, and a continuous stream of results will be received.
735  */
736 
737 int32_t ep_radar_d2gl_scfmcw_result_req(int32_t protocol_handle, uint8_t endpoint, uint32_t repeat_count)
738 {
739  /* build message to send */
740  uint8_t cmd_message[1+sizeof(uint32_t)];
741  uint16_t offset = 0;
742 
743  offset += protocol_write_payload_uint8(cmd_message, offset, MSG_RESULT_REQ);
744  offset += protocol_write_payload_uint32(cmd_message, offset, repeat_count);
745 
746  /* send message and process received response */
747  return protocol_send_and_receive(protocol_handle, endpoint,
749  cmd_message, offset);
750 }
751 
752 int32_t ep_radar_d2gl_scfmcw_adv_result_req(int32_t protocol_handle, uint8_t endpoint, uint32_t repeat_count)
753 {
754  /* build message to send */
755  uint8_t cmd_message[1+sizeof(uint32_t)];
756  uint16_t offset = 0;
757 
758  offset += protocol_write_payload_uint8(cmd_message, offset, MSG_ADV_RESULT_REQ);
759  offset += protocol_write_payload_uint32(cmd_message, offset, repeat_count);
760 
761  /* send message and process received response */
762  return protocol_send_and_receive(protocol_handle, endpoint,
764  cmd_message, offset);
765 }
766 
767 int32_t ep_radar_d2gl_scfmcw_get_shield_info_req(int32_t protocol_handle, uint8_t endpoint)
768 {
769  /* build message to send */
770  uint8_t cmd_message[1];
771  uint16_t offset = 0;
772 
773  offset += protocol_write_payload_uint8(cmd_message, offset, FMCW_MSG_GET_SHIELD_INFO_REQ);
774 
775  /* send message and process received response */
776  return protocol_send_and_receive(protocol_handle, endpoint,
778  cmd_message, offset);
779 }
780 
781 
782 
783 int32_t ep_radar_d2gl_scfmcw_get_raw_data_req(int32_t protocol_handle, uint8_t endpoint, uint32_t repeat_count)
784 {
785  /* build message to send */
786  uint8_t cmd_message[1+sizeof(uint32_t)];
787  uint16_t offset = 0;
788 
789  offset += protocol_write_payload_uint8(cmd_message, offset, FMCW_MSG_GET_RAW_DATA_REQ);
790  offset += protocol_write_payload_uint32(cmd_message, offset, repeat_count);
791 
792  /* send message and process received response */
793  return protocol_send_and_receive(protocol_handle, endpoint,
795  cmd_message, offset);
796 }
797 
798 
799 
800 /* --- End of File -------------------------------------------------------- */
uint32_t num_samples_per_chirp
Definition: radar_common.h:178
void ep_radar_d2gl_scfmcw_set_adv_result_cb(fmcw_adv_result_cnf_callback_t callback, void *p_context)
uint8_t baseband_gain_stage_bool
void ep_radar_d2gl_scfmcw_set_result_cb(fmcw_result_cnf_callback_t callback, void *p_context)
#define MSG_RESULT_CNF
void ep_radar_d2gl_scfmcw_set_shield_info_cb(fmcw_get_shield_info_cnf_callback_t callback, fmcw_get_shield_info_cnf_ctx_t *p_context)
#define FMCW_MSG_GET_RAW_DATA_REQ
const float * sample_data
Definition: radar_common.h:162
int32_t ep_radar_d2gl_scfmcw_para_value_def_req(int32_t protocol_handle, uint8_t endpoint)
int32_t ep_radar_d2gl_scfmcw_is_compatible_endpoint(int32_t protocol_handle, uint8_t endpoint)
This function checks if an endpoint in a device is a Radar D2GL endpoint.
This struct holds all information about a single frame of radar data.
Definition: radar_common.h:160
#define FMCW_MSG_GET_SHIELD_INFO_REQ
void(* fmcw_get_shield_info_cnf_callback_t)(fmcw_get_shield_info_cnf_ctx_t *p_context, int32_t protocol_handle, uint8_t endpoint, fmcw_get_shield_info_cnf_t *ps_temperature)
#define MSG_ADV_RESULT_CNF
#define FMCW_MSG_GET_SHIELD_INFO_CNF
#define MSG_RESULT_REQ
void ep_radar_d2gl_scfmcw_set_para_def_cb(fmcw_para_values_def_cnf_callback_t callback, fmcw_para_values_def_cnf_ctx_t *p_context)
#define MSG_PARA_VALUES_CNF
const char * ep_radar_get_error_code_description(uint16_t error_code)
const Endpoint_Definition_t ep_RadarD2GL_definition
Rx_Data_Format_t data_format
Definition: radar_common.h:203
int32_t protocol_send_and_receive(int32_t protocol_handle, uint8_t endpoint, const Endpoint_Definition_t *endpoint_definiton, const uint8_t *payload, uint16_t payload_size)
Definition: Protocol.c:957
void(* fmcw_para_values_def_cnf_callback_t)(fmcw_para_values_def_cnf_ctx_t *p_context, int32_t protocol_handle, uint8_t endpoint, fmcw_para_value_def_host_t *ps_para_values)
This is the callback type executed on a parameter value confirmation event, triggered,...
void(* fmcw_adv_result_cnf_callback_t)(void *p_context, int32_t protocol_handle, uint8_t endpoint, fmcw_adv_result_cnf_t *ps_para_values)
#define FMCW_MSG_GET_RAW_DATA_CNF
int32_t ep_radar_d2gl_scfmcw_get_shield_info_req(int32_t protocol_handle, uint8_t endpoint)
int32_t ep_radar_d2gl_scfmcw_para_set_value_req(int32_t protocol_handle, uint8_t endpoint, fmcw_para_values_t *p_data)
void ep_radar_d2gl_scfmcw_set_raw_data_cb(get_raw_data_cnf_callback_t callback, void *p_context)
int32_t ep_radar_d2gl_scfmcw_adv_result_req(int32_t protocol_handle, uint8_t endpoint, uint32_t repeat_count)
void(* get_raw_data_cnf_callback_t)(get_raw_data_cnf_ctx_t *p_context, int32_t protocol_handle, uint8_t endpoint, get_raw_data_cnf_t *ps_raw_data)
Definition: radar_common.h:214
#define MSG_PARA_VALUES_DEF_CNF
Rx_Data_Format_t
This enumeration type lists the possible formats of sampled radar data.
Definition: radar_common.h:46
int32_t protocol_is_endpoint_compatible(int32_t protocol_handle, uint8_t endpoint, const Endpoint_Definition_t *endpoint_definiton)
Definition: Protocol.c:927
#define MSG_PARA_SET_VALUES_REQ
void(* fmcw_para_values_cnf_callback_t)(void *p_context, int32_t protocol_handle, uint8_t endpoint, fmcw_para_values_t *ps_para_values)
This is the callback type executed on a parameter value confirmation event, triggered,...
int32_t ep_radar_d2gl_scfmcw_para_value_req(int32_t protocol_handle, uint8_t endpoint)
This function is used to request the parameter values,.
int32_t ep_radar_d2gl_scfmcw_result_req(int32_t protocol_handle, uint8_t endpoint, uint32_t repeat_count)
#define MSG_ADV_RESULT_REQ
fmcw_para_values_cnf_callback_t ep_radar_d2gl_scfmcw_set_para_value_cb(fmcw_para_values_cnf_callback_t callback, void *p_context, void **prev_context)
uint8_t number_of_chirps_per_frame
#define MSG_PARA_VALUES_DEF_REQ
#define MSG_PARA_VALUES_REQ
#define FMCW_MSG_GET_SHIELD_INFO_CNF_V2
int32_t ep_radar_d2gl_scfmcw_get_raw_data_req(int32_t protocol_handle, uint8_t endpoint, uint32_t repeat_count)
void(* fmcw_result_cnf_callback_t)(void *p_context, int32_t protocol_handle, uint8_t endpoint, fmcw_result_cnf_t *ps_para_values)
This file contains the API methods applicable generically to Industrial radar demo Distance2GoL.